package Printer;

import java.awt.Font;
import java.awt.Graphics;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterJob;

import javax.print.PrintService;
import javax.print.PrintServiceLookup;

public  class Printer2 implements Printable
{
  static Font font = new Font( Font.SANS_SERIF, Font.PLAIN, 20 );

  @Override
  public int print( Graphics g, PageFormat pageFormat, int pageIndex )
  {
    if ( pageIndex >= 2 )
      return Printable.NO_SUCH_PAGE;
    g.setFont( font );
    g.drawString( "Hallo auf Seite " + pageIndex, 100, 100 );
    return Printable.PAGE_EXISTS;
  }

	  public static void main(String args[])throws Exception
	  {
		  Printer2 p1 = new Printer2();
		  PrinterJob pjob = PrinterJob.getPrinterJob();
		  System.out.println(pjob.toString());
		  
		  pjob.setPrintable( p1 );
		  pjob.print();
	  }
	}

